const chalk = require('chalk');

module.exports = opt => {

  return async function authCookie(ctx, next) {
    console.log(chalk.blue.bgBlack.bold('authCookie middleware'));

    // 获取当前登录用户信息
    const userCookie = ctx.cookies.get('user');
    const user = JSON.parse(userCookie || '');


    if (user) {
      // 已登录，执行鉴权逻辑...
      const info = await ctx.model.Users.findOne({ account: user.account });
      if (info) {
        await next();
      }
      return;
    }
    return;
  };


};
